/**
 * @author: jever
 * @date: 2019/3/11
 * @description:  dashboard.js
 */

import React from 'react';
import {connect} from "react-redux";
import {NavBar} from "antd-mobile";
import NavLinkBar from '../navlink/navlink'
import {Switch, Route} from 'react-router-dom'
import Boss from '../boss/boss'
import Genius from '../genius/genius'
import User from '../user/user'
import Message from '../message/message'
import {getMsgList, recvMsg} from "../../redux/chat.redux";


@connect(
    state => state,
    {getMsgList, recvMsg}
)
class DashBoard extends React.Component {
    // constructor(props) {
    //     super(props)
    // }

    componentDidMount() {
        if (!this.props.chat.chatMsg.length) {
            this.props.getMsgList()
            this.props.recvMsg()
        }
    }

    render() {
        const {pathname} = this.props.location;
        const user = this.props.user;
        const navList = [
            {
                path: '/boss',
                text: '牛人',
                icon: 'boss',
                title: '牛人列表',
                component: Boss,
                hide: user.type === 'genius'
            },
            {
                path: '/genius',
                text: 'Boss',
                icon: 'job',
                title: 'BOSS列表',
                component: Genius,
                hide: user.type === 'boss'
            },
            {
                path: '/msg',
                text: '消息',
                icon: 'message',
                title: '消息列表',
                component: Message,
            },
            {
                path: '/me',
                text: '我',
                icon: 'user',
                title: '个人中心',
                component: User,
            }
        ];
        const curNav = navList.find(v => v.path === pathname)
        return (
            <div>
                <NavBar className={'fixed-header'} mode={'dark'}>
                    {curNav && curNav.title}
                </NavBar>
                <h2 style={{marginTop: '45px'}}>
                    <Switch>
                        {navList.map(v => (
                            <Route key={v.path} path={v.path} component={v.component}></Route>
                        ))}
                    </Switch>
                </h2>
                <NavLinkBar data={navList}></NavLinkBar>
            </div>
        )
    }
}

export default DashBoard